<template>
	
	<view id="app" style="padding-top:0rem;background-color: #F5F5F5;z-index: 9999999;" @touchmove.stop.prevent="clear">
	  <!-- 头部 -->
	 
	  <!-- 页面的主要内容 -->
		<view class="wrap wrap-sku" style="padding:25rpx;max-height:85vh;overscroll-behavior:none;">
			<view class="product-box">
				<!-- 图片显示区 -->
        <view class="item_img">
          <view style="display: flex;">
						<view class="item_img_image">
							<image v-if="props.selectObj.product_image" :src="props.selectObj.product_image" mode=""></image>
							<image v-else src="../../static/images/my/noPictures.png" mode=""></image>
						</view>
						<view style="margin-left:20rpx;" v-if="props.selectObj.product_id">
              <nut-price :price="props.selectObj.product_price" :decimal-digits="2" :thousands="false"/>
							<view style="display: flex;margin-top:10rpx;">
								<view class="tip">支持7天无理由退货</view>
								<view class="tip">30天价保</view>
							</view>
						</view>
            <view v-else>
              <view style="display: flex;margin-top:10rpx;">
                <view>请选择规格</view>

              </view>
            </view>
					</view>

          <!--地址选择区-->
					<view class="item_text" v-if="state.showAddress">
						<view style="font-size: 30rpx;font-weight: bold;">{{addressList[addressIndex].name}} {{addressList[addressIndex].phone}} {{addressList[addressIndex].area}}</view>
						<view style="font-size: 26rpx;margin-top:20rpx;">{{addressList[addressIndex].delivery}} {{addressList[addressIndex].date}}
							<text style="color:#E3391F;font-weight: bold;">[{{addressList[addressIndex].week}}]</text>
						</view>
					</view>

          <!--商品信息区-->
          <view class="item_text" v-if="props.selectObj.product_id" style="margin-top:10px;border-radius:10px;background-color: #fff;">
            <view class="info_title" style="font-size: 30rpx;font-weight: bold;">
              {{ props.selectObj.product_code }} {{ props.selectObj.product_name }}
            </view>
            <view class="info_lat" v-if="props.selectObj.diy_name" style="color:#E3391F;font-weight: bold;">
              已选： {{ props.selectObj.diy_name }}
            </view>
            <view class="info_code" style="font-size: 26rpx;margin-top:20rpx;">
              <text>存货编码： {{ props.selectObj.product_id }} </text>
              <text style="padding-left: 20rpx;">装箱规格:{{ props.selectObj.zxgg }}</text>
              <text style="padding-left: 20rpx;">起订量: {{ props.selectObj.qdl==0?'不限量':props.selectObj.qdl }} </text>
            </view>
          </view>
        </view>

				
				<!-- 规格选择区 -->
				<scroll-view scroll-y="true"  v-if="props.skuData.spec.length>0" style="margin-top:10px;border-radius:10px;overflow-y: auto;flex: 1; background-color: #fff;padding:5rpx 2rpx;max-height:43vh;">
					<view v-for="(specItem,n) in props.skuData.spec" :key="n">
						<view class="title">{{specItem.title}} <text class="sku_spec_memo"></text> </view>
						<ul>
							<li class="item"
									v-for="(oItem,index) in specItem.options"
									:key="index"
									@click="specificationBtn(specItem,oItem.title,n,index)"
									:class="[oItem.is_show?'':'noneActive',state.subIndex[n] == index?'productActive':'']"
							>{{oItem.title}}</li>
						</ul>
					</view>
          <!--长度宽度高度输入区域-->
          <view v-if="props.selectObj.pcs_dj === 'SQUARE'">
            <view class="title">尺寸要求 <text class="sku_spec_memo">（单位为mm）</text> </view>
						<!-- #ifdef MP-WEIXIN -->
						<view style="display: flex;">
							<view style="width: 50%;display: flex;">
								<view v-if="props.selectObj.door_height_options.length>0" style="display: flex;margin-top: 7px">
									<view class="uni-list-cell-left">
										长度：
									</view>
									<picker  @change="bindPickerChangeHeight" :value="index"
													:range="props.selectObj.door_height_options">
										<view class="uni-input">{{ door_height ||props.selectObj.door_height_options[0]}}</view>
									</picker>
								</view>

								<nut-input v-else label="长度：" label-width="45" :placeholder="props.selectObj.door_height" type="digit"
													 border="false" v-model="door_height" :disabled="disabled"></nut-input>
							</view>

							<view style="width: 50%;display: flex;">
								<nut-input v-if="props.selectObj.pcs_dj == 'SQUARE' && !props.selectObj.door_width_options.length>0"
													 label="宽度：" label-width="45" :placeholder="props.selectObj.door_width" v-model="door_width"
													 type="digit" :disabled="disabled" border="false"></nut-input>
								<view v-else style="display: flex;margin-top: 7px">
									<view class="uni-list-cell-left" >
										宽度：
									</view>
									<picker  @change="bindPickerChangeWidth" :value="index2" :range="props.selectObj.door_width_options">
										<view class="uni-input">{{ door_width || props.selectObj.door_width_options[0]}}</view>
									</picker>
								</view>
							</view>
						</view>
						<!-- #endif -->


						<!-- #ifdef H5 -->
						<view style="display: flex;" >
							<div style="width: 50%;display: flex;">
								<div v-if="props.selectObj.door_height_options.length>0" style="display: flex; margin-left: 20px;">
									<div class="uni-list-cell-left" style="display: flex">
										长度：
									</div>
									<select v-model="door_height" style="width: 90px;height: 30px">
										<option v-for="(option, index) in props.selectObj.door_height_options" :key="index" :value="option">
											{{ option }}
										</option>
									</select>
								</div>
								<div class="uni-form-item uni-column" v-else style="display: flex">
									<div class="uni-list-cell-left" style="display: flex">长度：</div>
									<input class="bordered-input" v-model="door_height" :placeholder="props.selectObj.door_height" type="number" :disabled="disabled" focus/>
								</div>
							</div>

							<div style="width: 50%;display: flex;">
								<div class="uni-form-item uni-column"
										 v-if="props.selectObj.pcs_dj === 'SQUARE' && !props.selectObj.door_width_options.length>0"
										 style="display: flex;">
									<div class="uni-list-cell-left" style="display: flex">宽度：</div>
									<input class="bordered-input" v-model="door_width" type="number" :placeholder="props.selectObj.door_width" :disabled="disabled" focus/>
								</div>

								<div v-else style="display: flex; ">
									<div class="uni-list-cell-left" style="display: flex">
										宽度：
									</div>
									<select style="width: 90px;height: 30px" v-model="door_width">
										<option
												v-for="(width, index) in props.selectObj.door_width_options"
												:key="index"
												:value="width"
										>
											{{ width }}
										</option>
									</select>
								</div>
							</div>
						</view>
						<!-- #endif -->
          </view>
          <view v-else-if="props.selectObj.pcs_dj === 'PCS'">
            <view class="title">尺寸要求 <text class="sku_spec_memo">（单位为mm）</text> </view>
						<!-- #ifdef MP-WEIXIN -->
						<view style="display: flex;">
							<view style="width: 50%;display: flex;">
								<view v-if="props.selectObj.door_height_options.length>0" style="display: flex;margin-top: 7px">
									<view class="uni-list-cell-left">
										长度：
									</view>
									<picker  @change="bindPickerChangeHeight" :value="index"
													:range="props.selectObj.door_height_options">
										<view class="uni-input">{{ door_height ||props.selectObj.door_height_options[0]}}</view>
									</picker>
								</view>

								<nut-input v-else label="长度：" label-width="45" :placeholder="props.selectObj.door_height" type="digit"
													 border="false" v-model="door_height" :disabled="disabled"></nut-input>
							</view>
						</view>
						<!-- #endif -->


						<!-- #ifdef H5 -->
						<view style="display: flex;" >
							<div style="width: 50%;display: flex;">
								<div v-if="props.selectObj.door_height_options.length>0" style="display: flex; margin-left: 20px;">
									<div class="uni-list-cell-left" style="display: flex">
										长度：
									</div>
									<select v-model="door_height" style="width: 90px;height: 30px">
										<option v-for="(option, index) in props.selectObj.door_height_options" :key="index" :value="option">
											{{ option }}
										</option>
									</select>
								</div>
								<div class="uni-form-item uni-column" v-else style="display: flex">
									<div class="uni-list-cell-left" style="display: flex">长度：</div>
									<input class="bordered-input" v-model="door_height" :placeholder="props.selectObj.door_height" type="number" :disabled="disabled" focus/>
								</div>
							</div>
						</view>
						<!-- #endif -->
          </view>

				</scroll-view>
				<view class="product-footer" style="z-index: 9999">
					<view style="display: flex;align-items: center;justify-content: space-between;">
						<view style="font-size:24rpx;color:#E3391F;">合计：
							<nut-price :price="totalAmount" :decimal-digits="2" :thousands="false"/>
						</view>
						<view style="display: flex;align-items: center;font-weight: bold;">
							<view style="font-size: 28rpx;color:#DB3922;margin-right:30rpx;font-weight: normal;" v-if="props.selectObj.qdl>1">
								({{props.selectObj.qdl}}件起订)
							</view>
							<nut-input-number  :step='1' :min="props.selectObj.qdl" v-model="buyNumber" button-size="30"
																 input-width="50" @change="numberInput"/>
						</view>
					</view>
					<view style="margin-top: 5px">
						<nut-button  block :type="props.buttonStyle.type" :disabled="props.buttonStyle.disabled" @click="addCartList">{{props.buttonStyle.name}}</nut-button>
					</view>

					<!--			<view  class="rightPay"></view>-->
				</view>
			</view>
		</view>
	  <!-- 页面结束 -->
	</view>

</template>

<script setup>
import {computed, onMounted, ref,watch} from 'vue'
	import {
		onShow,
		onLoad
	} from '@dcloudio/uni-app'
import {addCart} from "../../api/api";
	const emit = defineEmits(['getSelectedSku','closeDggSku'])


	const props = defineProps({
    addressList: {
      type: Object,
      default: [
        {
          name:'张三',
          phone:'13803116601',
          area:'河北省石家庄市裕华区裕翔街道',
          delivery:'京东快递',
          date:'9月23日',
          week:'周一',
        },
        {
          name:'李四',
          phone:'13803116602',
          area:'河北省石家庄市元氏县常山路',
          delivery:'京东快递',
          date:'9月24日',
          week:'周二',
        },
      ]
    },
    skuData:{ //规格
      type: Object,
      default: {
        spec: [],//规格列表
        fit_products: [],//赠送的产品
        products: [] //规格对应的商品列表
      }
    },
    selectObj: {//选中的商品信息
      type: Object,
      default: {product_price:0,qdl:1}
    },
    buttonStyle:{
      type: Object,
      default: {
        name: "立即购买",
        type: "primary",
        disabled:true
      }
    }
	})
	const addressIndex = ref(0)
  //模拟数据
 /* const data2=ref( {
    "spu": {
      "spu_id": 138831,
          "spu_name": "BK0028㎡蜂窝大板超值套餐，大气，上档次，还送线性浴霸",
          "default_sku": "100㎡,现代风"
    },
    "spec": [
      {
        "options": [
          {
            "id": "1036016184677502976",
            "title": "100㎡"
          },
          {
            "id": "1036016270438436864",
            "title": "68-80㎡"
          }
        ],
        "id": "1036016127010017280",
        "title": "房间大小",
        "cal_field": ""
      },
      {
        "options": [
          {
            "id": "1036016346229510144",
            "title": "现代风"
          },
          {
            "id": "1036016371235950592",
            "title": "中式风"
          },
          {
            "id": "1036016413590032384",
            "title": "地中海风"
          }
        ],
        "id": "1036016314382159872",
        "title": "风格",
        "cal_field": ""
      }
    ],
        "fit_products": [],
        "products": [
      {
        "pcs_dj": "单位",
        "product_image": "http://idh-image.oss-cn-hangzhou.aliyuncs.com/images/11726044950021.jpg",
        "old_product_price": 3980.000000,
        "product_price": 3980.00000000,
        "product_code": "BK002",
        "type_sales": 3980.000000,
        "isabled": "能",
        "door_height": "",
        "sku_value": "1036016184677502976,1036016346229510144",
        "product_id": "138831",
        "product_untl": "套",
        "sku_name": "100㎡,现代风",
        "diy_name": "100㎡,现代风",
        "spu_id": "138831",
        "pack_num": 1.00,
        "door_thickness": "",
        "zxgg": "1套/箱",
        "emb_value": 0,
        "product_size": "8平方蜂窝大板＋厨卫LED灯＋卫生间线性浴霸1台照明灯2台",
        "door_width": "",
        "product_name": "8㎡蜂窝大板超值套餐，大气，上档次，还送线性浴霸",
        "qdl": "0",
        "diy_json": "{\"product_id\":\"138831\",\"房间大小\":\"100㎡\",\"风格\":\"现代风\"}",
        "product_embprice": 0.00,
        "房间大小": "100㎡",
        "风格": "现代风"
      },
      {
        "pcs_dj": "单位",
        "product_image": "http://idh-image.oss-cn-hangzhou.aliyuncs.com/images/11726044950021.jpg",
        "old_product_price": 3980.000000,
        "product_price": 3980.00000000,
        "product_code": "BK002",
        "type_sales": 3980.000000,
        "isabled": "能",
        "door_height": "",
        "sku_value": "1036016184677502976,1036016371235950592",
        "product_id": "138831",
        "product_untl": "套",
        "sku_name": "100㎡,中式风",
        "diy_name": "100㎡,中式风",
        "spu_id": "138831",
        "pack_num": 1.00,
        "door_thickness": "",
        "zxgg": "1套/箱",
        "emb_value": 0,
        "product_size": "8平方蜂窝大板＋厨卫LED灯＋卫生间线性浴霸1台照明灯2台",
        "door_width": "",
        "product_name": "8㎡蜂窝大板超值套餐，大气，上档次，还送线性浴霸",
        "qdl": "0",
        "diy_json": "{\"product_id\":\"138831\",\"房间大小\":\"100㎡\",\"风格\":\"中式风\"}",
        "product_embprice": 0.00,
        "房间大小": "100㎡",
        "风格": "中式风"
      },
      {
        "pcs_dj": "单位",
        "product_image": "http://idh-image.oss-cn-hangzhou.aliyuncs.com/images/11726044950021.jpg",
        "old_product_price": 3980.000000,
        "product_price": 3980.00000000,
        "product_code": "BK002",
        "type_sales": 3980.000000,
        "isabled": "不能",
        "door_height": "",
        "sku_value": "1036016184677502976,1036016413590032384",
        "product_id": "138831",
        "product_untl": "套",
        "sku_name": "100㎡,地中海风",
        "diy_name": "100㎡,地中海风",
        "spu_id": "138831",
        "pack_num": 1.00,
        "door_thickness": "",
        "zxgg": "1套/箱",
        "emb_value": 0,
        "product_size": "8平方蜂窝大板＋厨卫LED灯＋卫生间线性浴霸1台照明灯2台",
        "door_width": "",
        "product_name": "8㎡蜂窝大板超值套餐，大气，上档次，还送线性浴霸",
        "qdl": "0",
        "diy_json": "{\"product_id\":\"138831\",\"房间大小\":\"100㎡\",\"风格\":\"地中海风\"}",
        "product_embprice": 0.00,
        "房间大小": "100㎡",
        "风格": "地中海风"
      },
      {
        "pcs_dj": "单位",
        "product_image": "http://idh-image.oss-cn-hangzhou.aliyuncs.com/images/11726044950021.jpg",
        "old_product_price": 3980.000000,
        "product_price": 3980.00000000,
        "product_code": "BK002",
        "type_sales": 3980.000000,
        "isabled": "能",
        "door_height": "",
        "sku_value": "1036016270438436864,1036016346229510144",
        "product_id": "138831",
        "product_untl": "套",
        "sku_name": "68-80㎡,现代风",
        "diy_name": "68-80㎡,现代风",
        "spu_id": "138831",
        "pack_num": 1.00,
        "door_thickness": "",
        "zxgg": "1套/箱",
        "emb_value": 0,
        "product_size": "8平方蜂窝大板＋厨卫LED灯＋卫生间线性浴霸1台照明灯2台",
        "door_width": "",
        "product_name": "8㎡蜂窝大板超值套餐，大气，上档次，还送线性浴霸",
        "qdl": "0",
        "diy_json": "{\"product_id\":\"138831\",\"房间大小\":\"68-80㎡\",\"风格\":\"现代风\"}",
        "product_embprice": 0.00,
        "房间大小": "68-80㎡",
        "风格": "现代风"
      },
      {
        "pcs_dj": "单位",
        "product_image": "http://idh-image.oss-cn-hangzhou.aliyuncs.com/images/11726044950021.jpg",
        "old_product_price": 3980.000000,
        "product_price": 3980.00000000,
        "product_code": "BK002",
        "type_sales": 3980.000000,
        "isabled": "能",
        "door_height": "",
        "sku_value": "1036016270438436864,1036016371235950592",
        "product_id": "138831",
        "product_untl": "套",
        "sku_name": "68-80㎡,中式风",
        "diy_name": "68-80㎡,中式风",
        "spu_id": "138831",
        "pack_num": 1.00,
        "door_thickness": "",
        "zxgg": "1套/箱",
        "emb_value": 0,
        "product_size": "8平方蜂窝大板＋厨卫LED灯＋卫生间线性浴霸1台照明灯2台",
        "door_width": "",
        "product_name": "8㎡蜂窝大板超值套餐，大气，上档次，还送线性浴霸",
        "qdl": "0",
        "diy_json": "{\"product_id\":\"138831\",\"房间大小\":\"68-80㎡\",\"风格\":\"中式风\"}",
        "product_embprice": 0.00,
        "房间大小": "68-80㎡",
        "风格": "中式风"
      },
      {
        "pcs_dj": "单位",
        "product_image": "http://idh-image.oss-cn-hangzhou.aliyuncs.com/images/11726044950021.jpg",
        "old_product_price": 3980.000000,
        "product_price": 3980.00000000,
        "product_code": "BK002",
        "type_sales": 3980.000000,
        "isabled": "能",
        "door_height": "",
        "sku_value": "1036016270438436864,1036016413590032384",
        "product_id": "138831",
        "product_untl": "套",
        "sku_name": "68-80㎡,地中海风",
        "diy_name": "68-80㎡,地中海风",
        "spu_id": "138831",
        "pack_num": 1.00,
        "door_thickness": "",
        "zxgg": "1套/箱",
        "emb_value": 0,
        "product_size": "8平方蜂窝大板＋厨卫LED灯＋卫生间线性浴霸1台照明灯2台",
        "door_width": "",
        "product_name": "8㎡蜂窝大板超值套餐，大气，上档次，还送线性浴霸",
        "qdl": "0",
        "diy_json": "{\"product_id\":\"138831\",\"房间大小\":\"68-80㎡\",\"风格\":\"地中海风\"}",
        "product_embprice": 0.00,
        "房间大小": "68-80㎡",
        "风格": "地中海风"
      }
    ]
  })
  const data=ref(data2)*/

  //const data=ref({})
  const state=ref({
        selectArr: [], //存放被选中的值
        subIndex: [], //是否选中 因为不确定是多规格还是单规格，所以这里定义数组来判断
        price: "", //选中规格的价钱
        showAddress:false,//是否显示地址
      }
  )
	const buyNumber = ref(1)
  const door_height = ref()
  const door_width = ref()
  const door_thickness = ref('')
	const array=	ref(['中国', '美国', '巴西', '日本'])
	const index = ref(0)
	const index2 = ref(0)
	const disabled = ref(false)

	onMounted(() => {
	  console.log('onMounted执行。。。',props);
	  setDefaultOption();
	});

  const totalAmount=computed(()=>{
		let a, b = (Number(door_height?.value) && Number(door_width?.value)) ? (parseFloat(door_height?.value) * parseFloat(door_width?.value)) / 1000000 : 1;
		if (props.skuData.spec.length > 0) {
			a = parseFloat(props.selectObj.product_price) * parseFloat(buyNumber?.value) * b;
			console.log("b=" + b);
		} else {
			a = parseFloat(props.selectObj.product_price) * parseFloat(buyNumber?.value);
		}
    if(a<=0){
      props.buttonStyle.disabled=true;
    }else{
      props.buttonStyle.disabled=false;
    }
    //console.log("单价="+state.value.selectObj.product_price+"数量="+buyNumber.value);
    return a;
  })

	const bindPickerChangeHeight=(e)=> {
	index.value = e.detail.value
	door_height.value=props.selectObj.door_height_options[index.value]
	}
	const bindPickerChangeWidth=(e)=> {
	index2.value = e.detail.value
	door_width.value=props.selectObj.door_width_options[index2.value]
	}
	const numberInput=(val,event)=>{

    console.log('数量变化：'+val)
	}

  const specificationBtn=(specItem,item, n, index)=>{
   // console.log("state.value.selectArr="+JSON.stringify(state.value.selectArr)+"n="+n+" index="+index);
    // 判断是否选的长或宽，是则赋值给下面输入框
    if (specItem.cal_field==='length'){
      door_height.value = item
    }else if (specItem.cal_field==='width'){
      door_width.value = item
    }
    if (state.value.selectArr[n] != item) {
      state.value.selectArr[n] = item; //当前规格选中,赋值为选项的名字(蓝色、黑色)
      state.value.subIndex[n] = index; //设置此项为选中
    } else {
      state.value.selectArr[n] = "";
      state.value.subIndex[n] = -1; //去掉选中的颜色
    }
    checkItem()

  }
	 const checkItem=()=>{
     //let option = data.value.simulatedDATA.specifications;
     let option = props.skuData.spec;
     //console.log("option=",JSON.stringify(option));
     let result = []; //定义数组储存被选中的值
     for (let i in option) {
       //初始化被选中的数组，如果此类别没被选中，则赋值为空，如果有3个类别，则数组长度为3
       result[i] = state.value.selectArr[i] ? state.value.selectArr[i] : "";
     }

     //便利每个类别的每个小项
     for (let i in option) {
       let last = result[i]; //把选中的值存放到字符串last去
       for (let k in option[i].options) {
         result[i] = option[i].options[k].title; //获取每个小项的值(如：红色、蓝色)，并临时存放于result[i]，存在直接覆盖，不存在往里面添加name值
         option[i].options[k].is_show = isMay(result); //result数组每一次修改都将计算一次是否可以选择，添加字段isShow来判断是否可以选择
       }
       result[i] = last; //还原，目的是记录点下去那个值，避免下一次执行循环时被覆盖
     }
     //console.log("修改option=",JSON.stringify(option));
     //console.log("修改后result=",JSON.stringify(result));

     //console.log("修改后产品值=",JSON.stringify(props.skuData.products[result]));
     let selectObj = props.skuData.products[result];
     //如果可获取sku，则显示当前sku价格
     if (selectObj) {
       //state.value.price = props.skuData.products[result].product_price || "";
      // props.selectObj={};
       //state.value.skuSelectObj=selectObj;//props.skuData.products[result];
       emit('getSelectedSku', selectObj);
       //console.log("state.value.skuSelectObj=",state.value.skuSelectObj);
       //如果起订量大于1，则输入数量为起订量
       if(buyNumber.value<selectObj.qdl){
         buyNumber.value=selectObj.qdl;
       }
     }
	 }
	 
	 const isMay=(result)=>{
    console.log("result=",JSON.stringify(result));
		 for (let i in result) {
		     if (result[i] == "") {
		       return true; //如果数组里有为空的值，则表示未被全部选择，无法获取sku，直接返回true
		     }
		   }
		   //result选满，可获取sku，根据初始化时shopItemInfo的difference[i].difference键值对(200,蓝色)可获取sku信息
		   return props.skuData.products[result].isabled == '不能' ? false : true; //匹配选中的数据的库存，若不为空返回true反之返回false
	}

  //设置默认选项
  const setDefaultOption=()=>{
    //设置默认选项
      if(props.selectObj.diy_name){
      let option = props.skuData.spec;
      let result = []; //定义数组储存被选中的值
      for (let i in option) {
        result[i] = state.value.selectArr[i] ? state.value.selectArr[i] : "";
      }
      let isNullOpt=true;
      for(let i in result){
        if(result[i] != ""){
          isNullOpt=false;
          break;
        }
      }
      if(isNullOpt){
        console.log("设置默认选项"+props.selectObj.diy_name);
        result=props.selectObj.diy_name.split(",");
        for (let i in option) {
          for (let k in option[i].options) {
            if(option[i].options[k].title == result[i]){
              state.value.selectArr[i] = result[i];
              state.value.subIndex[i]=k;
              break;
            }
          }
        }
      }
    }
    if (props.selectObj?.door_height?.split("-")[0]===props.selectObj?.door_height?.split("-")[1]){
      door_height.value = props.selectObj?.door_height?.split("-")[0]
      disabled.value =true
     }
    if (props.selectObj?.door_width?.split("-")[0]===props.selectObj?.door_width?.split("-")[1]){
      door_width.value = props.selectObj?.door_width?.split("-")[0]
      disabled.value=true
     }
  }

const addCartList = () => {
  let session = uni.getStorageSync('session');
  if (door_height.value >Number(props.selectObj.door_height.split('-')[1]) ||door_height.value <Number(props.selectObj.door_height.split('-')[0]) ){
    uni.showToast({
      title:'输入长度超出限制',
      icon: 'error'
    })
    return false
  }
  if (door_width.value >Number(props.selectObj.door_width.split('-')[1]) ||door_width.value <Number(props.selectObj.door_width.split('-')[0])){
    uni.showToast({
      title:'输入宽度超出限制',
      icon: 'error'
    })
    return false
  }
  if (
      (!isNaN(parseFloat(buyNumber.value)) &&
          Number.isInteger(parseFloat(buyNumber.value)) &&
          parseFloat(buyNumber.value) >= 0)
  ) {
    console.log('sa')
  } else {
    uni.showToast({
      title:'请输入有效的整数',
      icon: 'error'
    })
    return false
  }
  // 获取宽度
  let param = {
    // 接口
    proname: 'IN0K07',
    // 门店编码
    Agent_Code: session.DWDM,
    // 存货编码
    Product_Code: props.selectObj.product_id,
    // 单价
    product_price: props.selectObj.product_price,
    // 长度
    Product_MJ: door_height.value,
    product_height: door_height.value,
    // 宽度
    Product_Width: door_width.value,
    product_width: door_width.value,
    // 厚度
    product_thickness: door_thickness.value,
    // 数量
    Product_Num: buyNumber.value,
    //  备注
    // Product_Memo:this.bz,
    // 订单编号
    Back_Code: 'XS' + session.DWDM, //如果是编辑订单，则订单编号在skuData中获取
    // 多规格 - 定制属性
    attribute: props.selectObj.diy_name,
    // 定制属性
    diy_value: props.selectObj.sku_value,
    // 排序号
    d_PXH: '',
    // 启用折扣
    QYZK: '10',
  }
  if (props.skuData.back_code){
    param.Back_Code = props.skuData.back_code
  }
  console.log("props.skuData.back_code",props.skuData.back_code)
  console.log("加入购物车请求报文", param)
  addCart(param).then((res => {
    console.log("加入购物车响应报文", res)
    if (res.result == 'ok') {
      uni.showToast({
        title: '加入成功！',
        icon: 'none'
      })
      //state.value.showBasic = false
      //show_one_sku.value = false
      emit('closeDggSku', 'addCart');
    }
  }))
}

//加入本地缓存的购物车
const addStorageCart = () => {
  let session = uni.getStorageSync('session');
  //一个产品信息
  let record = {
    // 门店编码
    Agent_Code: session.DWDM,
    // 存货编码
    Product_Code: props.selectObj.product_id,
    // 单价
    product_price: props.selectObj.product_price,
    // 长度
    Product_MJ: '',
    product_height: '',
    // 宽度
    Product_Width: '',
    product_width: '',
    // 厚度
    product_thickness: '',
    // 数量
    Product_Num: buyNumber.value,
    //小计
    back_amount:totalAmount.value,
    //  备注
    // Product_Memo:this.bz,
    // 订单编号
    Back_Code: 'XS' + session.DWDM,
    // 多规格 - 定制属性
    attribute: props.selectObj.diy_name,
    // 定制属性
    diy_value: props.selectObj.sku_value,
    // 启用折扣
    QYZK: '10',
  }
  console.log("加入缓存购物车请求报文", record)
  let shopCart=uni.getStorageSync("shopCart");
  console.log("本地缓存的购物车:"+JSON.stringify(shopCart));
  if(shopCart == ""){
    let newShopCart=[];
    newShopCart.push(record);
    uni.setStorageSync("shopCart",newShopCart);
  }else{
    console.log("存在吗？",shopCart.includes(record))
    if(!shopCart.includes(record)) {
      shopCart.push(record);
      uni.setStorageSync("shopCart",shopCart);
    }

  }
  shopCart=uni.getStorageSync("shopCart");
  console.log("添加产品后缓存的购物车",shopCart);

}


	const clear = ()=>{
		
	}

</script>


<style scoped lang="scss">
	.title{
		font-size:30rpx;
		font-weight: bold;
		margin:10rpx;
	}
	.item{
		font-size:28rpx;
		padding:20rpx 40rpx;
		color: #383838;
		background-color: #F2F2F2;
		border-radius: 15rpx;
		display: inline-block;
		margin:10rpx 10rpx;
	}
	.productActive{
		color: #D53D42;
		background-color: #FCEDEA;
		border: 1rpx solid #D53D42;
	}
  .noneActive{
    opacity: 0.5;
    color: #777;
    text-decoration: line-through;
    background-color: #F2F2F2;
  }
	.item_img_image image{
		width:80px;
		height:80px;
		border-radius: 10px;
	}
	.tip{
		color:#E3391F;
		border:1rpx solid #E3391F;
		border-radius: 5rpx;
		font-size: 20rpx;
		margin-right:10rpx;
	}
	.item_text{
		padding:20rpx;
	}
	.code{
		color:#8B8B8B;
		font-size: 24rpx;
		margin-left:20rpx;
	}
  .sku_spec_memo{
    font-size: 28rpx;
    color:#DB3922;
    margin-right:30rpx;
    font-weight: normal;
  }
	.rightPay{
		color:#FEFBFA;
		background-color: #F43A45;
		text-align: center;
		border-radius: 40rpx;
		padding:20rpx 0;
		font-weight: bold;
		margin-top:10rpx;
	}
	.product-footer{
		background-color: #fff;
		padding:20rpx;
		padding-bottom: 0;
		margin-top: auto; /* 这会将 .product-footer1 推到底部 */
		bottom:22px;
		width:94%;
	}
	.numberInput{
		background-color: #F2F2F2;
		font-size:30rpx;
		width:60px;
		height:35px;
		color:black;
		font-weight: bold;
		margin:0 15rpx;
		text-align: center;
	}
	.bordered-input {
		//margin-top: 5px;
		width: 100px;
		height: 35px;
		border: 2px solid #ccc; /* 设置边框为2像素宽，颜色为浅灰色 */
		border-radius: 4px; /* 可选：设置边框圆角 */
		box-sizing: border-box; /* 确保内边距和边框被包含在元素的总宽度和高度内 */
	}
  .uni-input {
    border: 1px solid #000; /* 设置1px宽的实线边框，颜色为黑色 */
    border-radius: 4px; /* 边框圆角，根据需要调整 */
    box-sizing: border-box; /* 确保边框和内边距不会增加元素的总宽度和高度 */
    /* 其他样式... */
  }

</style>